<?php

/**
    * 无限级分类
    * @access public 
    * @param Array $data     //数据库里获取的结果集 
    * @param Int $pid             
    * @param Int $count       //第几级分类
    * @param Int $parent_key  //父ID字段名
    * @return Array $treeList      
 */
class MenuTool{
    //存放无限分类结果如果一页面有多个无限分类可以使用 Tool::$treeList = array(); 清空
    static public $treeList = array();
   
    static public function tree(&$data, $pid = 0, $count = 1, $parent_key = 'pid') 
    {
        foreach ($data as $key => $value) {
            if ($value[$parent_key] == $pid) {
                $value['count'] = $count;
                self::$treeList[] = $value;
                unset($data[$key]);
                self::tree($data, $value['id'], $count + 1, $parent_key);
            } 
        }
        
        return self::$treeList ;
    }
    
}
    